<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MVP SDK 测试</title>
</head>
<body>
    <div id="app">
        <h1>MVP SDK 测试页面</h1>
        
        <!-- 登录表单 -->
        <div class="test-section">
            <h2>登录测试</h2>
            <input type="text" id="username" placeholder="用户名">
            <input type="password" id="password" placeholder="密码">
            <button onclick="testLogin()">测试登录</button>
        </div>

        <!-- 用户信息测试 -->
        <div class="test-section">
            <h2>用户信息测试</h2>
            <button onclick="testGetUserProfile()">获取用户信息</button>
            <div id="userProfileResult"></div>
        </div>

        <!-- 数据上报测试 -->
        <div class="test-section">
            <h2>数据上报测试</h2>
            <button onclick="testReportData()">测试数据上报</button>
        </div>

        <!-- 配置获取测试 -->
        <div class="test-section">
            <h2>配置获取测试</h2>
            <input type="text" id="configKey" placeholder="配置键名">
            <button onclick="testGetConfig()">获取配置</button>
            <div id="configResult"></div>
        </div>
    </div>

    <script type="module">
        import { MvpClient } from './lib/sdk/mvpClient.ts';

        // 初始化 SDK
        const client = new MvpClient({
            baseURL: '',
            apiKey: ''
        });

        // 登录测试
        window.testLogin = async () => {
            try {
                const username = document.getElementById('username').value;
                const password = document.getElementById('password').value;
                const result = await client.login(username, password);
                alert(`登录成功：${JSON.stringify(result)}`);
            } catch (error) {
                alert(`登录失败：${error.message}`);
            }
        };

        // 获取用户信息测试
        window.testGetUserProfile = async () => {
            try {
                const profile = await client.getUserProfile();
                document.getElementById('userProfileResult').textContent = 
                    JSON.stringify(profile, null, 2);
            } catch (error) {
                alert(`获取用户信息失败：${error.message}`);
            }
        };

        // 数据上报测试
        window.testReportData = async () => {
            try {
                await client.reportData({
                    eventType: 'test-event',
                    timestamp: Date.now(),
                    data: {
                        page: 'test-page',
                        action: 'test-action'
                    }
                });
                alert('数据上报成功');
            } catch (error) {
                alert(`数据上报失败：${error.message}`);
            }
        };

        // 获取配置测试
        window.testGetConfig = async () => {
            try {
                const configKey = document.getElementById('configKey').value;
                const config = await client.getConfig(configKey);
                document.getElementById('configResult').textContent = 
                    JSON.stringify(config, null, 2);
            } catch (error) {
                alert(`获取配置失败：${error.message}`);
            }
        };
    </script>

    <style>
        .test-section {
            margin: 20px;
            padding: 20px;
            border: 1px solid #ccc;
            border-radius: 5px;
        }
        input, button {
            margin: 5px;
            padding: 5px;
        }
        #userProfileResult, #configResult {
            margin-top: 10px;
            padding: 10px;
            background-color: #f5f5f5;
            white-space: pre-wrap;
        }
    </style>
</body>
</html>
